<?php
/**
 * Created by PhpStorm.
 * User: DD
 * Date: 2016/4/22
 * Time: 17:51
 */

namespace app\admin\controller;


use app\admin\services\CodeToolService;
use app\common\util\Util;
use app\common\controller\Base;

class CodeTool extends Base
{
    /**
     * @var CodeToolService
     */
    protected $_service;

    protected function _setService()
    {
        $this->_service = new CodeToolService();
    }

    public function index()
    {
        $this->assign('tableList', $this->_service->getTableList());
        return $this->fetch('codeTool/index');
    }

    public function getCode()
    {
        list($name, $title) = explode('=>', $_GET['name']);
        return $this->returnJson($this->_service->getCode(Util::parseName(ucfirst($name), 1), $title));
    }

    public function getCodeForWeixin()
    {
        list($name, $title) = explode('=>', $_GET['name']);
        return $this->returnJson($this->_service->getCodeForWeixin(Util::parseName(ucfirst($name), 1), $title));
    }

    public function createFile()
    {
        list($name, $title) = explode('=>', $_GET['name']);
        return $this->returnJson($this->_service->createCodeFile(Util::parseName(ucfirst($name), 1), $title));
    }

    public function createFileForWeixin()
    {
        list($name, $title) = explode('=>', $_GET['name']);
        return $this->returnJson($this->_service->createFileForWeixin(Util::parseName(ucfirst($name), 1), $title));
    }

    public function weixin()
    {
        $this->assign('tableList', $this->_service->getTableList());
        return $this->fetch();
    }


}